package com.drcurd.service.impl;

import com.drcurd.entity.Employee;
import com.drcurd.dto.EmployeeQueryDTO;
import com.drcurd.mapper.EmployeeMapper;
import com.drcurd.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EmployeeServiceImpl implements EmployeeService {
    
    @Autowired
    private EmployeeMapper employeeMapper;
    
    @Override
    public List<Employee> getAllEmployees() {
        return employeeMapper.selectAll();
    }
    
    @Override
    public Employee getEmployeeById(Long id) {
        return employeeMapper.selectById(id);
    }
    
    @Override
    public boolean addEmployee(Employee employee) {
        return employeeMapper.insert(employee) > 0;
    }
    
    @Override
    public boolean updateEmployee(Employee employee) {
        return employeeMapper.update(employee) > 0;
    }
    
    @Override
    public boolean deleteEmployee(Long id) {
        return employeeMapper.deleteById(id) > 0;
    }
    
    @Override
    public List<Employee> getEmployeesByCondition(EmployeeQueryDTO queryDTO) {
        return employeeMapper.selectByCondition(queryDTO);
    }
    
    @Override
    public int getEmployeeCountByCondition(EmployeeQueryDTO queryDTO) {
        return employeeMapper.selectCountByCondition(queryDTO);
    }
    
    @Override
    public List<Employee> getEmployeesByPage(Integer page, Integer size) {
        int offset = (page - 1) * size;
        return employeeMapper.selectByPage(offset, size);
    }
    
    @Override
    public int getEmployeeCount() {
        return employeeMapper.selectCount();
    }
} 